<?

require_once  $_SERVER['DOCUMENT_ROOT']."/../_lib/base/common.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.hotel_instances_you.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.destinations.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.hotels.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.template.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.tree.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.photos.php"; 
require_once SITE_ROOT_PATH."/_lib/classes/class.user_auth.php";

	// See if user is logged in 
	$user_auth = new user_auth();
	$user_auth->user_auth_cp();


	$template = new template();





// FUNCTION // Display select suppliers instances
function display_home(){


		
?>


<h2>Flagged YouTravel(YOU) Hotel Instances</h2>


<?
if($GLOBALS['note']){
	echo display_message($GLOBALS['note']);
}
?>


<div class="border_box">



<h3>Search Flagged Accommodation</h3>


<form action="<?= $_SERVER['PHP_SELF'] ?>" >

<input type="hidden" name="search" value="true" />

<table class="libra">
<tr>
<td width="100">Prefix</td>
<td>
<select name="prefix">	
<option value=""></option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
<option value="e">e</option>
<option value="f">f</option>
<option value="g">g</option>
<option value="h">h</option>
<option value="i">i</option>
<option value="j">j</option>
<option value="k">k</option>
<option value="l">l</option>
<option value="m">m</option>
<option value="n">n</option>    
<option value="o">o</option>
<option value="p">p</option>
<option value="q">q</option>
<option value="r">r</option>    
<option value="s">s</option>
<option value="t">t</option>
<option value="u">u</option>
<option value="v">v</option>
<option value="w">w</option>
<option value="x">x</option>
<option value="y">y</option>
<option value="z">z</option>
</select>
</td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" value="" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="submit"/></td>
</tr>
</table>


</form>

</div>

<br />



<?

	$search_params['prefix'] = $_REQUEST['prefix'];
	$search_params['name'] = $_REQUEST['name'];
	$search_params['resort_id'] = $_REQUEST['resort_id'];
	
	$hotel_instances_you = new hotel_instances_you();
	$values = $hotel_instances_you->search_flagged_instances($search_params);
		
if(!empty($values)){
?>

<table class="aqua">
  <tr>
    <th width="200">Name</th>
    <th width="200">Destination</th>
    <th width="100">Resort</th>
	<th  width="200">Date flagged</th>
	<th width="100">Actions</th>
</tr>

<? foreach($values as $value){ ?>
  <tr>
    <td><?= $value['hotel_name'] ?></td>
    <td><?= $value['destination'] ?></td>
    <td><?= $value['resort'] ?></td>
    <td><?= date('d/m/Y', $value['instance_date']) ?></td>
	<td><a href="<?= $_SERVER['PHP_SELF']."?action=view&instance_id=".$value['instance_id'] ?>">View</a>|<a onclick="return confirm('Do you really want to delete this instance?')" href="<?= $_SERVER['PHP_SELF']."?action=delete&instance_id=".$value['instance_id'] ?>">Delete</a></td>
</tr>
<? } ?>

</table>




<?
}

}











// FUNCTION // Display details of the instance
function display_instance(){

    $hotel_instances_you = new hotel_instances_you();
	
	$params['instance_id'] = $_GET['instance_id'];
	$values = $hotel_instances_you->get_flagged_instance($params);
	$values = $values[0];
	unset($params);
	
	
?>


<h2>Flagged YouTravel(YOU) Hotel Instances</h2>

<h3>Instance details</h3>

<?
if($GLOBALS['note']){
	echo display_message($GLOBALS['note']);
}
?>

<div class="border_box">



<fieldset><legend>Instance Details</legend></fieldset>


<table class="libra">
  <tr>
    <td width="200"><strong>hotel_name </strong></td>
    <td><?= $values['hotel_name'] ?></td>
  </tr>
  <tr>
    <td><strong>hotel_id_youtravel</strong></td>
    <td><?= $values['hotel_id_youtravel'] ?></td>
  </tr>
  <tr>
    <td><strong>youtravel_rating</strong></td>
    <td><?= $values['youtravel_rating'] ?></td>
  </tr>
  <tr>
    <td><strong>official_rating</strong></td>
    <td><?= $values['official_rating'] ?></td>
  </tr>

  <tr>
    <td><strong>board_type</strong></td>
    <td><?= $values['board_type'] ?></td>
</tr>
<tr>
    <td><strong>hotel_description</strong></td>
    <td><?= $values['hotel_description'] ?></td>
</tr>
<tr>
    <td><strong>hotel_photosdfg</strong></td>
    <td><?
    
if($values['hotel_photos']){
	echo "<img src='".$values['hotel_photos']."' />";
}

	
	
	?></td>
</tr>
<tr>
    <td><strong>country</strong></td>
    <td><?= $values['country'] ?></td>
</tr>
<tr>
    <td><strong>destination</strong></td>
    <td><?= $values['destination'] ?></td>
</tr>
<tr>
    <td><strong>resort</strong></td>
    <td><?= $values['resort'] ?></td>
</tr>
<tr>
    <td><strong>instance_date</strong></td>
    <td><?= date('d/m/y',$values['instance_date']) ?></td>
</tr>
</table>

<br />



<fieldset>
<legend>You Travel description</legend>
</fieldset>

<table class="libra">
  <tr>
    <td width="200"><strong>Download YouTravel description</strong></td>
    <td><a href="hotels_download_you.php?HID=<?= $values['hotel_id_youtravel'] ?>&instance_id=<?= $values['instance_id'] ?>">View full description</a></td>
  </tr>
</table>





<br />



<fieldset>
<legend>Link instance to exsiting hotel tree ID</legend> 
</fieldset>


<form action="<?= $_SERVER['PHP_SELF'] ?>" method="get">

<input type="hidden" name="action" value="append_confirm" />
<input type="hidden" name="instance_id" value="<?= $values['instance_id'] ?>" />


<table class="libra">
  <tr>
    <td width="200"><strong>Link instance to tree ID</strong></td>
    <td><input type="text" name="tree_id" value=""  /></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="submit" value="submit" name="submit" /></td>
  </tr>
</table>


</form>

</div>
<?



}





// FUNCTION // Display instance append confirmation form
function display_append_confirm(){

	$destinations = new destinations();
	$photos = new photos();	
	$hotels = new hotels();
	$hotel_instances_you = new hotel_instances_you();

	// Get hotel details
	$params['tree_id'] = $_GET['tree_id'];
	$values_acc = $hotels->get_hotel($params);
	unset($params);
	
	// Get instance details
	$params['instance_id'] = $_GET['instance_id'];
	$values_instance = $hotel_instances_you->get_flagged_instance($params);
	$values_instance = $values_instance[0];
	unset($params);
	
	
	
?>


<h2>Flagged YouTravel(YOU) Hotel Instances</h2>

<h3>Link Instance</h3>

<p>Please confirm that you want to link the following instances:</p>


<div class="border_box">



<fieldset><legend>Instance Details</legend></fieldset>


<table class="libra">
  <tr>
    <td width="200"><strong>hotel_name </strong></td>
    <td><?= $values_instance['hotel_name'] ?></td>
  </tr>
  <tr>
    <td><strong>hotel_id_youtravel</strong></td>
    <td><?= $values_instance['hotel_id_youtravel'] ?></td>
  </tr>
  <tr>
    <td><strong>youtravel_rating</strong></td>
    <td><?= $values_instance['youtravel_rating'] ?></td>
  </tr>
  <tr>
    <td><strong>official_rating</strong></td>
    <td><?= $values_instance['official_rating'] ?></td>
  </tr>

  <tr>
    <td><strong>board_type</strong></td>
    <td><?= $values_instance['board_type'] ?></td>
</tr>
<tr>
    <td><strong>hotel_description</strong></td>
    <td><?= $values_instance['hotel_description'] ?></td>
</tr>
<tr>
    <td><strong>hotel_photos</strong></td>
    <td><?
    
if($values_instance['hotel_photos']){
	echo "<img src='".$values_instance['hotel_photos']."' />";
}

	
	
	?></td>
</tr>
<tr>
    <td><strong>country</strong></td>
    <td><?= $values_instance['country'] ?></td>
</tr>
<tr>
    <td><strong>destination</strong></td>
    <td><?= $values_instance['destination'] ?></td>
</tr>
<tr>
    <td><strong>resort</strong></td>
    <td><?= $values_instance['resort'] ?></td>
</tr>
<tr>
    <td><strong>instance_date</strong></td>
    <td><?= date('d/m/y',$values_instance['instance_date']) ?></td>
</tr>
</table>

<br />

<h3>With the following accommodation:</h3>


<fieldset><legend>Hotel Details</legend></fieldset>


<table class="libra">
  <tr>
    <td width="200"><strong>Name</strong></td>
    <td><?= $values_acc['name'] ?></td>
  </tr>
  <tr>
    <td><strong>Description</strong></td>
    <td><?= nl2br($values_acc['description']) ?></td>
  </tr>
  <tr>
    <td><strong>Resort</strong></td>
    <td><?
	
		$params['tree_id'] = $values_acc['parent_id'];
		$resort_values = $destinations->get_destination($params);
		unset($params);
		echo $resort_values['name']." (".$resort_values['tree_id'].")";
	 
	 ?></td>
  </tr>
  <tr>
    <td><strong>Photos</strong></td>
    <td><?
	

	$current_photos = $photos->get_photos($values_acc['tree_id']);
	
    if(!$current_photos){
		echo "<img src='".UPLOAD_HTTP_PERM."na.gif'>";
	}else{
		
		for($i = 0; $i < 6; $i++){
		
			echo "<img src='".UPLOAD_HTTP_PERM.$current_photos[$i]['photo_url_thumb']."' class='thumbnail' name='thumb".$value['photo_id']."' />";
		
		}
        
    }
	
	
	?></td>
  </tr>
</table>

<br />


<form action="<?= $_SERVER['PHP_SELF'] ?>" method="get">

	<input type="hidden" name="action" value="append" />
    
	<input type="hidden" name="instance_id" value="<?= $_GET['instance_id'] ?>" />
	<input type="hidden" name="tree_id" value="<?= $_GET['tree_id'] ?>" />

    <input type="button" value="Cancel" />
    <input type="submit" name="submit" value="Yes" class="form_button" /></td>


</form>

</div>

<?



}







switch ($_REQUEST['action']) {

	default;
	
		$template->head_control();
		display_home();
		$template->foot_control();
		
	break;

	case "view";
		$template->head_control();
        display_instance();
		$template->foot_control();
	break;
	

	case "append_confirm";
	
	
		$hotels = new hotels();
		$params['tree_id'] = $_GET['tree_id'];
		$hotel_values = $hotels->get_hotel($params);
		if(!empty($hotel_values)){
		
			$template->head_control();
			display_append_confirm();
			$template->foot_control();
		
		}else{
		
			$my_message = array();
			$my_message['type'] = 'neg';
			$my_message['message'] = "There was a problem with the form.";
			$my_message['list'] = array('The tree ID was not a hotel.');
			$GLOBALS['note'] = $my_message;
			$template->head_control();
			display_instance();
			$template->foot_control();
			
		}
	
		
	break;

	case "append";
	
		$hotel_instances_you = new hotel_instances_you();
		
		$params = array();
		$params['tree_id'] = $_REQUEST['tree_id'];
		$params['instance_id'] = $_REQUEST['instance_id'];
		$hotel_instances_you->link_instance($params);
	
		$my_message = array();
		$my_message['type'] = 'pos';
		$my_message['message'] = "The instance was succesfully linked";
		$GLOBALS['note'] = $my_message;
			
		$template->head_control();
		display_home($message);
		$template->foot_control();
		
	break;
	
	case "delete";
		$hotel_instances_you = new hotel_instances_you();
		$params = array();
		$params['instance_id'] = $_REQUEST['instance_id'];
		$hotel_instances_you->deleted_flagged_instance($params['instance_id']);
		header('Location:hotels_flagged_you.php?deleted');
	break;
	
	case "delete";
		
		$my_message = array();
		$my_message['type'] = 'pos';
		$my_message['message'] = "Instance succesfully deleted";
		$GLOBALS['note'] = $my_message;
		$template->head_control();
		display_home();
		$template->foot_control();
	break;
}



?>